<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">

<link href="../../bootstrap/css/bootstrap.min.css" type="text/css" rel="stylesheet" />
<script type="text/javascript" src="../../js/jquery.js"></script>
<script type="text/javascript" src="../../bootstrap/js/bootstrap.min.js"></script>
	<script src="/js/vue.js"></script>
	<script src="/js/axios.min.js"></script>
	<script src="/element-ui/lib/index.js"></script>
	<link rel="stylesheet" href="/element-ui/lib/theme-chalk/index.css">
<script type="text/javascript">

	//默认情况下取消和保存按钮是隐藏的
	var cancelAndSaveBtnDefault = true;
	
	$(function(){
		$("#remark").focus(function(){
			if(cancelAndSaveBtnDefault){
				//设置remarkDiv的高度为130px
				$("#remarkDiv").css("height","130px");
				//显示
				$("#cancelAndSaveBtn").show("2000");
				cancelAndSaveBtnDefault = false;
			}
		});
		
		$("#cancelBtn").click(function(){
			//显示
			$("#cancelAndSaveBtn").hide();
			//设置remarkDiv的高度为130px
			$("#remarkDiv").css("height","90px");
			cancelAndSaveBtnDefault = true;
		});
		
		$(".remarkDiv").mouseover(function(){
			$(this).children("div").children("div").show();
		});
		
		$(".remarkDiv").mouseout(function(){
			$(this).children("div").children("div").hide();
		});
		
		$(".myHref").mouseover(function(){
			$(this).children("span").css("color","red");
		});
		
		$(".myHref").mouseout(function(){
			$(this).children("span").css("color","#E6E6E6");
		});
	});
	
</script>

</head>
<body>
	<div id="app">

	<!-- 返回按钮 -->
	<div style="position: relative; top: 35px; left: 10px;">
		<a href="javascript:void(0);" onclick="window.history.back();"><span class="glyphicon glyphicon-arrow-left" style="font-size: 20px; color: #DDDDDD"></span></a>
	</div>
	
	<!-- 大标题 -->
	<div style="position: relative; left: 40px; top: -30px;">
		<div class="page-header">
			<h3>市场活动-{{activity.name}} <small>{{activity.startDate}} ~ {{activity.endDate}}</small></h3>
		</div>
		
	</div>
	
	<br/>
	<br/>
	<br/>

	<!-- 详细信息 -->
	<div style="position: relative; top: -70px;">
		<div style="position: relative; left: 40px; height: 30px;">
			<div style="width: 300px; color: gray;">所有者</div>
			<div style="width: 300px;position: relative; left: 200px; top: -20px;"><b>{{activity.ownerUser?activity.ownerUser.name:''}}</b></div>
			<div style="width: 300px;position: relative; left: 450px; top: -40px; color: gray;">名称</div>
			<div style="width: 300px;position: relative; left: 650px; top: -60px;"><b>{{activity.name}}</b></div>
			<div style="height: 1px; width: 400px; background: #D5D5D5; position: relative; top: -60px;"></div>
			<div style="height: 1px; width: 400px; background: #D5D5D5; position: relative; top: -60px; left: 450px;"></div>
		</div>

		<div style="position: relative; left: 40px; height: 30px; top: 10px;">
			<div style="width: 300px; color: gray;">开始日期</div>
			<div style="width: 300px;position: relative; left: 200px; top: -20px;"><b>{{activity.startDate}}</b></div>
			<div style="width: 300px;position: relative; left: 450px; top: -40px; color: gray;">结束日期</div>
			<div style="width: 300px;position: relative; left: 650px; top: -60px;"><b>{{activity.endDate}}</b></div>
			<div style="height: 1px; width: 400px; background: #D5D5D5; position: relative; top: -60px;"></div>
			<div style="height: 1px; width: 400px; background: #D5D5D5; position: relative; top: -60px; left: 450px;"></div>
		</div>
		<div style="position: relative; left: 40px; height: 30px; top: 20px;">
			<div style="width: 300px; color: gray;">成本</div>
			<div style="width: 300px;position: relative; left: 200px; top: -20px;"><b>{{activity.cost}}</b></div>
			<div style="height: 1px; width: 400px; background: #D5D5D5; position: relative; top: -20px;"></div>
		</div>
		<div style="position: relative; left: 40px; height: 30px; top: 30px;">
			<div style="width: 300px; color: gray;">创建者</div>
			<div style="width: 500px;position: relative; left: 200px; top: -20px;"><b>{{activity.createUser?activity.createUser.name:''}}&nbsp;&nbsp;</b><small style="font-size: 10px; color: gray;">{{activity.createTime}}</small></div>
			<div style="height: 1px; width: 550px; background: #D5D5D5; position: relative; top: -20px;"></div>
		</div>
		<div style="position: relative; left: 40px; height: 30px; top: 40px;">
			<div style="width: 300px; color: gray;">修改者</div>
			<div style="width: 500px;position: relative; left: 200px; top: -20px;"><b>{{activity.editUser?activity.editUser.name:''}}&nbsp;&nbsp;</b><small style="font-size: 10px; color: gray;">{{activity.editTime}}</small></div>
			<div style="height: 1px; width: 550px; background: #D5D5D5; position: relative; top: -20px;"></div>
		</div>
		<div style="position: relative; left: 40px; height: 30px; top: 50px;">
			<div style="width: 300px; color: gray;">描述</div>
			<div style="width: 630px;position: relative; left: 200px; top: -20px;">
				<b>
					{{activity.description}}
				</b>
			</div>
			<div style="height: 1px; width: 850px; background: #D5D5D5; position: relative; top: -20px;"></div>
		</div>
	</div>
	
	<!-- 备注 -->
	<div style="position: relative; top: 30px; left: 40px;">
		<div class="page-header">
			<h4>备注</h4>
		</div>
		
		<!-- 备注1 -->
		<div v-for="item in remarks" class="remarkDiv" style="height: 60px;">
			<img :title="item.createUser?item.createUser.name:''" src="../../image/user-thumbnail.png" style="width: 30px; height:30px;">
			<div style="position: relative; top: -40px; left: 40px;" >
				<h5>{{item.noteContent}}</h5>
				<font color="gray">市场活动</font> <font color="gray">-</font> <b>{{activity.name}}</b> <small style="color: gray;">
				{{item.createTime}} 由{{item.createUser?item.createUser.name:''}}</small>
				<div style="position: relative; left: 500px; top: -30px; height: 30px; width: 100px; display: none;">
					<a class="myHref" @click="editClick(item)" href="javascript:void(0);"><span class="glyphicon glyphicon-edit" style="font-size: 20px; color: #E6E6E6;"></span></a>
					&nbsp;&nbsp;&nbsp;&nbsp;
					<a class="myHref" @click="del(item.id)" href="javascript:void(0);"><span class="glyphicon glyphicon-remove" style="font-size: 20px; color: #E6E6E6;"></span></a>
				</div>
			</div>
		</div>
		

		<div id="remarkDiv" style="background-color: #E6E6E6; width: 870px; height: 90px;">
			<form role="form" style="position: relative;top: 10px; left: 10px;">
				<textarea id="remark" v-model="remark.noteContent" class="form-control" style="width: 850px; resize : none;" rows="2"  placeholder="添加备注..."></textarea>
				<p id="cancelAndSaveBtn" style="position: relative;left: 737px; top: 10px; display: none;">
					<button id="cancelBtn" type="button" class="btn btn-default">取消</button>
					<button type="button" class="btn btn-primary" @click="saveRemark">保存</button>
				</p>
			</form>
		</div>
	</div>
	<div style="height: 200px;"></div>
	</div>
	<script>
		new Vue({
			el:"#app",
			data:{
				activity: {},
				remarks:[],
				remark:{//修改/添加的备注信息
					id:undefined,
					noteContent:undefined,
					createBy:undefined,
					editBy:undefined,
					activityId:undefined
				}
			},
			methods:{
				del(id){//根据备注的主键删除备注
					axios.delete(`/activityRemark?remarkId=${id}`).then(resp=>{
						let data=resp.data;
						if (data.code==200){
							this.$message({
								type:"success",
								message:"操作成功"
							});
							//刷新备注列表
							this.getRemarkByActivityId();
						}else{
							this.$message({
								type:"error",
								message:data.msg
							});
						}
					})
				},
				editClick(item){//点击修改备注
					// console.log(item)
					this.remark={...item}
					//设置修改人
					let user=JSON.parse(sessionStorage.getItem("user"));
					this.remark.editBy=user.id;
				},
				saveRemark(){//保存备注
					if (!this.remark.id){//添加
						let user=JSON.parse(sessionStorage.getItem("user"));
						//设置创建人的id
						this.remark.createBy=user.id
						//设置市场活动的id
						this.remark.activityId=sessionStorage.getItem("activityId");
					}
					axios({
						method:this.remark.id?"put":"post",
						url:"/activityRemark",
						data:this.remark
					}).then(resp=>{
						let data=resp.data;
						if (data.code==200){
							this.$message({
								type:"success",
								message:"操作成功"
							});
							//刷新备注列表
							this.getRemarkByActivityId();
							//置空上次输入的备注
							this.remark.noteContent=undefined;
							//备注的主键置空
							this.remark.id=undefined;
						}
					})
				},
				initData(){//根据主键获取市场活动详细信息
					let id=sessionStorage.getItem("activityId");
					axios.get("/activity/getById?id="+id).then(resp=>{
						let data=resp.data;
						this.activity=data.result;
					})
				},
				getRemarkByActivityId(){//根据活动的id获取备注
					axios.get("/activityRemark?activityId="+sessionStorage.getItem("activityId")).then(resp=>{
						let data=resp.data;
						this.remarks=data.result
					})
				}
			},
			created(){
				this.initData();//根据主键获取市场活动详细信息
				this.getRemarkByActivityId()//根据活动的id获取备注
			}
		})
	</script>
</body>
</html>